// pages/themes/themes.js
// var postsData = require('../../model/themes.js')
var searchValue = ''

Page({
  data: {
    // loading
    hidden: true,
    scrollBottm:0,
    searchValue:'',
    posts_key:[]
  },

  scrolltolower: function (e) {
    this.setData({
      scrollBottm:0
    })
  },

  searchValueInput: function (e) {
    const that = this;
    that.setData({
      searchValue: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    const that = this;
    console.log(wx.getStorageSync('name'))
    that.setData({
      searchValue: wx.getStorageSync('name')
    })
    that.search()
  },

  search: function (options) {
    var that = this;
    wx.showLoading({
      title: "获取书本信息",
      mask: true
    }),
    wx.request({
      url: 'https://wxbook.youjp.xin/magic/start',
      data: {
        bookName: that.data.searchValue
      },
      header:{
        'content-type':'application/json'
      },
      success(res){
        console.log(res.data);
        that.setData({
          posts_key: res.data
        })
        wx.hideLoading()
      }
    })
  },
  //跳转传参
  content: function (e) {
    var that = this
    wx.setStorage({
      key: "url",
      data: e.currentTarget.dataset.url
    })
  } ,
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})